home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Memory / DIMM Config&Interleave v1.1 / TestBanks.c < prev   
Encoding:
Text File  |  1997-10-13  |  3.5 KB  |  110 lines  |  [TEXT/CWIE]

  1. /* TestBanks.c */
  2. //
  3. //    Bo3b:  This is the main routine for testing to see if the Ram banks
  4. //        are interleaved or not. It tests the situation by using the Hammerhead
  5. //        magic registers.  
  6. //
  7. //        Hence the magic numbers of bankN and interleaveMask.
  8. //
  9. //        It maps out the data into the input array, which is used as the raw data
  10. //        to print out the DIMM setup.  This part just returns what is in the 
  11. //        HammerHead registers, because the mapping to DIMM slot is machine
  12. //        dependent.
  13.  
  14. /* Bit 2 on = Interleave for both SIMMs */
  15. /*                                    =>    9500  | 75&8500    */
  16. /* 1C0:    Bank  0/1 -    Motherboard        =>      Motherboard    */
  17. /* 200:    Bank  2/3 -    DIMM 0/1 Front    =>    A1/B1 | B4/A4    */
  18. /* 240:    Bank  4/5 -    DIMM 0/1 Back     =>      A1/B1 | B4/A4    */
  19. /* 280:    Bank  6/7 -    DIMM 2/3 Front    =>      A2/B2 | B3/A3    */
  20. /* 2C0:    Bank  8/9 -    DIMM 2/3 Back     =>      A2/B2 | B3/A3    */
  21. /* 300:    Bank 10/11-    DIMM 4/5 Front    =>      A3/B3 | B2/A2    */
  22. /* 340:    Bank 12/13-    DIMM 4/5 Back     =>      A3/B3 | B2/A2    */
  23. /* 380:    Bank 14/15-    DIMM 6/7 Front    =>      A4/B4 | B1/A1     */
  24. /* 3C0:    Bank 16/17-    DIMM 6/7 Back     =>      A4/B4 | B1/A1    */
  25. /* 400:    Bank 18/19-    DIMM 8/9 Front    =>      A5/B5            */
  26. /* 440:    Bank 20/21-    DIMM 8/9 Back     =>      A5/B5            */
  27. /* 480:    Bank 22/23-    DIMM 10/11 Front=>    A6/B6            */
  28. /* 4C0:    Bank 24/25-    DIMM 10/11 Back =>    A6/B6            */
  29.  
  30.  
  31. #include <types.h>
  32. #include <gestalt.h>
  33. #include <errors.h>
  34.  
  35. #include "Interleave.h"
  36.  
  37.  
  38. #define interleaveMask    0x04
  39. #define adrs1Mask        0x01
  40. #define adrs1Shift        8 
  41. #define MegPerAdrs        4
  42.  
  43.  
  44. // Formerly:
  45. //void TestBanks (short *InterleaveBank, short *RAMbank);
  46.  
  47.  
  48. //==============================================================
  49. // Get the ram bank info by playing with the HammerHead registers.
  50. //     Sets up the RAMBankDescriptors.
  51.  
  52. OSErr
  53. GetPhysicalRAMBankInfo(RAMBankDescriptorPtr  theBanks, UInt32  fullMemSize, Ptr  hammerHeadBase)
  54. {
  55.     Ptr            bankN;
  56.     short         i;
  57.     
  58.     // We are on the proper hardware, go ahead and fiddle with the naughty bits.
  59.     
  60.     bankN = hammerHeadBase + 0x1C0;
  61.     
  62.     for (i=0; i<=25; i++)
  63.     {
  64.         theBanks[i].bankIsInterleaved = *bankN & interleaveMask;
  65.         theBanks[i].bankSize = (*bankN) & adrs1Mask ;
  66.         bankN = bankN + 0x10;
  67.         theBanks[i].bankSize = (theBanks[i].bankSize << adrs1Shift) + (*bankN);
  68.         bankN = bankN + 0x10;
  69.     } 
  70.     
  71.     // Now theBanks.bankSize fields are set up with the address (upper bits)  
  72.     //    of the starting location of each bank. This doesn't match the interface,
  73.     //    where we want to give each bank's individual size.  Go
  74.     //     through and calculate the size of each bank by determining deltas.
  75.     //     And multiply by 4, so that they become actual Meg counts.
  76.     // If the bank is interleaved, copy half the meg count up to the next
  77.     //    bank.  And, mark the second as interleaved too. This normalizes the 
  78.     //    banks, from the data received by fiddling with bits.
  79.     
  80.     for (i = 0; i < 25; i++)
  81.     {
  82.         theBanks[i].bankSize = (theBanks[i+1].bankSize - theBanks[i].bankSize) * MegPerAdrs;
  83.     }
  84.         
  85.     // For the very last element, we need the full memory size, and subtract
  86.     //    the starting address at theBanks[25] in order to figure it's delta size.
  87.     //     We need to divide fullMemSize by 4, since the other params are 4 Meg chunks.
  88.     
  89.     theBanks[25].bankSize = (fullMemSize / 4 - theBanks[25].bankSize) * MegPerAdrs;
  90.  
  91.     // If a bank is interleaved, copy half the meg count up to the next
  92.     //    bank.  This normalizes the banks, from the data received by 
  93.     //    fiddling with bits.
  94.     
  95.     for (i = 0; i < 25; i++)
  96.     {
  97.         if (theBanks[i].bankIsInterleaved) {
  98.             theBanks[i+1].bankSize = theBanks[i].bankSize / 2;
  99.             theBanks[i].bankSize = theBanks[i+1].bankSize;
  100.         }
  101.     }    
  102.     
  103.     return (noErr);
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.